package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@Slf4j
@Api("菜品添加")
@RestController("adminDishController")
@RequestMapping("/admin/dish")
public class DishController {
    @Autowired
    private DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result add(@RequestBody DishDTO dishDTO) {
        dishService.add(dishDTO);
        return Result.success();
    }

    /**
     * 菜品条件查询及分页
     */
    @ApiOperation("分页及条件查询")
    @GetMapping("/page")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO) {
        log.info("分页查询：{}", dishPageQueryDTO);
        PageResult pageResult = dishService.page(dishPageQueryDTO);//后续步骤定义
        return Result.success(pageResult);
    }

    /**
     * 售卖状态修改
     */
    @ApiOperation("售卖状态修改")
    @PostMapping("/status/{status}")
    public Result status(@PathVariable Integer status, Long id) {
        log.info("状态修改 1为启售 0为停售：{},{}", status, id);
        dishService.updateStatus(status, id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @ApiOperation("批量上传")
    @DeleteMapping
    public Result delete(@RequestParam List<Long> ids) {
        log.info("批量删除：{}", ids);
        dishService.delete(ids);
        return Result.success();
    }

    /**
     * 菜品修改回显
     */


    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Long id) {
        log.info("根据ID回显：{}",id);
        DishVO dishVO = dishService.selectById(id);
        return Result.success(dishVO);
    }
    /**
     * 修改功能
     */
    @ApiOperation("菜品修改")
    @PutMapping
    public Result update(@RequestBody DishDTO dishDTO){
        dishService.update(dishDTO);
        return Result.success();
    }
    /**
     * 根据菜品类型ID查询
     */
    @GetMapping("/list")
    public Result selectByCategoryId(Long categoryId){
        log.info("类型ID：{}",categoryId);
        List<Dish> dishList = dishService.selectByCategoryId(categoryId);
        return Result.success(dishList);
    }
}
